/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.perficient.ibuzz.service;

import com.google.api.client.http.HttpTransport;
import com.perficient.ibuzz.model.Message;
import com.perficient.ibuzz.model.MessageSender;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Allan.Ke
 */
public class BuzzMessageSender implements MessageSender{
    
    private HttpTransport transport;
    private BuzzActivity activity;

    public BuzzMessageSender(HttpTransport transport){
       this.transport = transport;
    }

    public void setActivity(BuzzActivity activity)
    {
        this.activity = activity;
    }
    
    @Override
    public void sendMessage(Message message) {
        try {
            if (this.activity == null)
                activity = new BuzzActivity();
            
            activity.object = new BuzzObject();
            activity.object.content = message.getText();
            activity.post(transport);
        } catch (Exception ex) {
            Logger.getLogger(BuzzMessageSender.class.getName()).log(Level.SEVERE, null, ex);
            throw new ServiceException(ex);            
        }
    }

}
